package com.example.flashApp.usage

import android.app.usage.UsageStatsManager
import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.Date

class UsageRepository(context: Context) {

    private val usageDao = UsageDatabase.getDatabase(context).usageDao()
    private val usageStatsManager = context.getSystemService(Context.USAGE_STATS_SERVICE) as UsageStatsManager

    suspend fun getUsageBetweenDates(start: Date, end: Date): List<UsageEntity> {
        return usageDao.getUsageBetweenDates(start, end)
    }

    suspend fun insertUsage(usageEntity: UsageEntity) {
        usageDao.insert(usageEntity)
    }

    suspend fun deleteOldData(olderThan: Date) {
        usageDao.deleteOlderThan(olderThan)
    }
}
